package org.irri.smta.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name="ROLE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Role extends TimestampedAutoIdEntity implements Comparable<Role> {

	private static final long serialVersionUID = 1L;
	
	public static final Long DEFAULT_ROLE_ID = 3L;

	@NotNull
	@Column(name = "NAME", nullable = false)
    @Size(min = 1, max = 100)
	private String name;

	@Column(name = "DESCRIPTION", nullable = true)
	@Size(min = 0, max = 2000)
	private String description;

	public Role() {
		super();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = StringUtils.substring(name.trim(), 0, 100);
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = StringUtils.substring(description.trim(), 0, 2000);
	}

	@Override
	public int compareTo(Role o) {
		if (o != null) {
			return this.name.compareTo(o.name);
		}
		return 0;
	}

}
